// pages/mine/mine.js
import Dialog from '@vant/weapp/dialog/dialog';
import {
  hnavigateTo,
  hgetStorage,
  hsetStorage,
  hshowLoading,
  hhideLoading
} from '../../static/htools.wx'
import {
  hrequestGet
} from '../../static/hunit.wx'
import api from '../../assets/api'
const {
  getUserInfo,
  getDeptExt
} = api
Page({
  data: {
    isAuthor: 0,
    deptExtInfo: {},
    fileList: [],
    userName: '',
    userHeadPic: '',
    userPhone: '',
    userArea: ''
  },
  onLoad(options) {
    if (this.data.isAuthor == 1) {
      this.getDeptExt()
    }
  },
  onShow() {
    this.setData({
      isAuthor: hgetStorage('isAuthor'),
      userName: hgetStorage('userName'),
      userHeadPic: hgetStorage('userHeadPic'),
      userPhone: hgetStorage('userPhone'),
      userArea: hgetStorage('deptArea')
    })
    if (this.data.isAuthor == 1) {
      this.getDeptExt()
    }
  },
  //点击登录按钮判断是否授权
  getAuthorInfo(e) {   
    if (e.detail.rawData) {
      hsetStorage('isAuthor', 2)
      hnavigateTo('/pages/login/login')
    } else {
      return false
    }
  },
  //获取企业基本信息
  async getDeptExt() {
    //let deptId = hgetStorage('deptId')
    let _jsonData = {
      deptId:hgetStorage('deptId')
    }
    let _res = await hrequestGet(getDeptExt,_jsonData);
    // console.log(_res);
    this.setData({
      deptExtInfo: _res.data
    })
  },
  //点击完善查看
  goBaseInfo(e) {
    let _id = e.currentTarget.dataset.id
    hnavigateTo('/pages/baseInfo/baseInfo?id=' + _id)
  },
  //点击去填报
  goEeclare() {
    hnavigateTo('/pages/declare/declare')
  },
  // 点击设置
  goSeting() {
    hnavigateTo('/pages/logout/logout')
  },
  openHelp() {
    hshowLoading()
    wx.downloadFile({
      url: "https://ghlinker.sansunt.com/pdf/UserManual_dianliyonghu.pdf",
      success:(res)=> {
        let Path = res.tempFilePath //返回的文件临时地址，用于后面打开本地预览所用
        wx.openDocument({
          filePath: Path,
          success:(res)=> {
            this.setData({
              loading: false,
            })
            hhideLoading()
          }
        })
      },
      fail:(res)=> {
        wx.showToast({
          title: '文档加载失败',
          icon: 'none',
        })
        this.setData({
          loading: false,
        })
      }
    })
  },
})